import { defineStore } from 'pinia';
export const usetabsStore = defineStore('tabs', {
  state: () => ({
    menuid: 1,//当前侧边栏菜单ID，系统默认ID为1
    menu: [],//当前页面侧边栏菜单
    tab: [],//目前所有保存的页签
    activetab: '',//当前选中页签的名称
    activetabindex: ''//当前选选中页签的index
  }),
  actions: {
    //设置当前menu
    setmenu(menus: any) {
      this.menu = menus;
    },
    //设置当前menuid
    setmenuid(menuid: number) {
      this.menuid = menuid;
    },
    //设置当前选中tab
    setActiveTab(activetabs: string) {
      this.activetab = activetabs;
    },
    //设置当前选中tabindex
    setActiveTabindex(activetabindex: string) {
      this.activetabindex = activetabindex;
    },
    //设置当前tabs
    settabs(tabs: any) {
      this.tab = tabs;
    },
    //新增tab
    addtab(tab: any) {
      this.tab.push(tab);
    },
    //移除tab
    desctab(tab: any) {
      this.tab.splice(this.tab.indexOf(tab), 1);
    },
    setnull() {
      this.tab = [],
        this.activetab = '',
        this.activetabindex = '';
    }
  },
  persist: {
    enabled: true,  // 启用持久化
    strategies: [
      {
        key: 'tabs',  // 设置 activetabindex 存储的 key
        storage: localStorage,     // 使用 localStorage 存储
        paths: ['menuid','menu', 'tab', 'activetab', 'activetabindex'],
      },
    ]
  },
});
